//家族js


function showInfo(text) {
    $("body").addClass("overflow-hidden");
    $(".info-text").html(text);
    $(".modal-info").fadeIn(300);

    setTimeout(function () {
        $("body").removeClass("overflow-hidden");
        $(".modal-info").fadeOut(300);
    }, 1000);
}
$(".info-sure").click(function (e) {
    e.preventDefault();
    $("body").removeClass("overflow-hidden");
    $(".modal-info").hide();
});

function openHref(url) {
    $(".info-sure-2").click(function (e) {
        e.preventDefault();
        window.location.href = url;
    });
}
(function ($) {
    //获取url参数的封装函数
    //decodeURI() 和 decodeURIComponent()
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&|#)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) {
            return decodeURIComponent(r[2]);
        }
        return null;
    };
    $.mygetUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");

        var r = window.location.hash.substr(1).match(reg);
        if (r != null) {
            return decodeURIComponent(r[2]);
        }
        return null;
    };
})(jQuery);


var server = 'http://139.199.23.160:8080/qmzb';
var server = 'http://139.199.23.160:8080/qmzb';
var page = 1; //当前页
var isEnd = false; //是否到底
var isLoading = false; //是否加载下一页
var touch_py = 0;
var rate = 0;

$("body")[0].addEventListener('touchmove', function (ev) {

    var screenhight = window.screen.height;
    window.onscroll = function () {
        if (screenhight + document.body.scrollTop > parseFloat(document.body.scrollHeight) + 100) {
            $(" #pullUp .pullUpIcon-down ").addClass("down");
            isLoading = true;
        } else {

            isLoading = false;
        }
    }

});

$("body")[0].addEventListener('touchend', function (ev) {

    if (isLoading & !isEnd) {
        $(" #pullUp .pullUpIcon-down ").removeClass("down").hide();
        $(" #pullUp .pullUpIcon-loading ").show();
        FamilyList.dataInit();
        //加载下一页

        isLoading = false;
    }




});
var login_uid = $.getUrlParam("login_uid");

var FamilyList = {
    page: 1,
    keyword: "",
    data_arry: [],
    pagesize: 20,
    icon_i: 1,
    dataInit: function () {

        this.dataLoadFUC(this.keyword, this.page);
    },
    dataLoadFUC: function (keyword, page) {
        var form_2 = new FormData();
        form_2.append("keyword", keyword);
        form_2.append("page", page);
            alert(111);
           $.ajax({
            type: "POST",
        
            dataType: "JSON",
            url: server + "/check/getFamilyList",
            data: form_2,
             dataType: 'JSON',  
            cache: false,  
            processData: false,  
            contentType: false  ,
            success: function (data) {
                if (data.code == 200) {
                var li_frag = document.createDocumentFragment();
                data_arr = data.data.list;
                if (data.data.allpages == FamilyList.page) {
                    isEnd = true;
                }


                FamilyList.page++;

                for (var i = 0; i < data.data.list.length; i++) {
                    var element = data.data.list[i];
                    var li = document.createElement("li");

                       var li_html=  [
                          
                "<a href='family_detail.html?login_uid=",login_uid,"&id=",element.id,"'",
                    '><div class="container app-family-list-con clearfloat">',
                       ' <div class="app-family-left">',
                           "<i class='app-family-icon app-family-icon-",FamilyList.icon_i>3?FamilyList.icon_i : FamilyList.icon_i++,"'></i>",
                        ' <img src=',element.logo,' alt="">',
                        '</div>',
                        '<div class="app-family-mid">',
                            '<p>',element.familyName,'</p>',
                            '<span>ID', element.id,'</span>',
                        '</div>',
                       ' <div class="app-family-right">',
                            '家族收益: <span>',element.monthTotalTicket,'民票</span>',
                        ' </div>',
                    '</div>',
                '</a>',
          
                        ].join("");
                        console.log(li_html);
                 
                    $(li).html(
                      li_html
                    );
                         
                       
                    li_frag.appendChild(li);
                }
                //for 结束
                $(" #pullUp").show();
                if (isEnd) {

                    $(" #pullUp .pullUpIcon ").hide();
                    $(" #pullUp .pullUpIcon-loading ").hide();
                    $(".pullUpLabel").html("没有更多了!");
                } else {
                    $(" #pullUp .pullUpIcon-down ").show();
                    $(".pullUpLabel").html("上拉加载更多");
                }
                $(".js_fl_list").append(li_frag);



            } else {
                //失败
                showInfo("服务器异常");
            }
            }
               
        });


    
    },
    SearchdataLoadFUC: function (keyword, page) {
        var form_2 = new FormData();
        form_2.append("keyword", keyword);
        form_2.append("page", page);
        
           $.ajax({
            type: "POST",
        
            dataType: "JSON",
            url: server + "/check/getFamilyList",
            data: form_2,
             dataType: 'JSON',  
            cache: false,  
            processData: false,  
            contentType: false  ,
            success: function (data) {
                if (data.code == 200) {
                var li_frag = document.createDocumentFragment();
                data_arr = data.data.list;
                if (data.data.allpages == FamilyList.page) {
                    isEnd = true;
                }


                FamilyList.page++;

                for (var i = 0; i < data.data.list.length; i++) {
                    var element = data.data.list[i];
                    var li = document.createElement("li");
                    var li_html=  [
                          
                "<a href='family_detail.html?login_uid=",login_uid,"&id=",element.id,"'",
                    '><div class="container app-family-list-con clearfloat">',
                       ' <div class="app-family-left">',
                           "<i class='app-family-icon app-family-icon-",FamilyList.icon_i>3?FamilyList.icon_i : FamilyList.icon_i++,"'></i>",
                        ' <img src=',element.logo,' alt="">',
                        '</div>',
                        '<div class="app-family-mid">',
                            '<p>',element.familyName,'</p>',
                            '<span>ID', element.id,'</span>',
                        '</div>',
                       ' <div class="app-family-right">',
                            '家族收益: <span>',element.monthTotalTicket,'民票</span>',
                        ' </div>',
                    '</div>',
                '</a>',
          
                        ].join("");
                        console.log(li_html);
                    $(li).html(
                      li_html
                    );
                  

                
                       
                    li_frag.appendChild(li);
                }
                //for 结束
                $(" #pullUp").show();
                if (isEnd) {

                    $(" #pullUp .pullUpIcon ").hide();
                    $(" #pullUp .pullUpIcon-loading ").hide();
                    $(".pullUpLabel").html("没有更多了!");
                } else {
                    $(" #pullUp .pullUpIcon-down ").show();
                    $(".pullUpLabel").html("上拉加载更多");
                }
                $(".js_fl_list").html(li_frag);



            } else {
                //失败
                showInfo("服务器异常");
            }
            }
               
        });
    },
    search: function () {
        $(".js_family-_search").keyup(function () {
            var keyword = $(this).val();
            FamilyList.keyword = keyword;
            FamilyList.page = 1;
            FamilyList.SearchdataLoadFUC(FamilyList.keyword, FamilyList.page);
        });
    }

};



$(function () {


    FamilyList.dataInit();
    FamilyList.search();
});